﻿// ***********************************************************************
// Assembly         : OSS.BIM
// Author           : tian_
// Created          : 09-03-2018
//
// Last Modified By : tian_
// Last Modified On : 09-04-2018
// ***********************************************************************
// <copyright file="ProjectForm.cs" company="北京智帆高科科技有限公司">
//     Copyright © 北京智帆高科科技有限公司 2018
// </copyright>
// <summary></summary>
// ***********************************************************************
using System;
using System.Windows.Forms;
using OSS.BIM.Model;
using ZFGK.Utility;

namespace OSS.BIM.UI.Forms
{
    /// <summary>
    /// Class ProjectForm.
    /// </summary>
    /// <seealso cref="DevExpress.XtraEditors.XtraForm" />
    public partial class ProjectForm : DevExpress.XtraEditors.XtraForm
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ProjectForm"/> class.
        /// </summary>
        /// <param name="project">The project.</param>
        public ProjectForm(Project project)
        {
            InitializeComponent();
            Project = project;
        }

        /// <summary>
        /// Gets or sets the project.
        /// </summary>
        /// <value>The project.</value>
        public Project Project { get; set; }

        /// <summary>
        /// Handles the Load event of the ProjectForm control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void ProjectForm_Load(object sender, EventArgs e)
        {
            txeName.EditValue = Project.Name;
            txeLongitude.EditValue = Project.Longitude;
            txeLatitude.EditValue = Project.Latitude;
            txeElevation.EditValue = Project.Elevation;
            txeRotation.EditValue = Project.Rotation.RadianToAngle();
            meRemark.EditValue = Project.Remark;
        }

        /// <summary>
        /// Handles the Click event of the btnOk control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txeName.Text.Trim()))
            {
                ZfMessageUtil.ShowError("名称不能为空!");
                txeName.Focus();
                return;
            }
            if (txeLongitude.EditValue == null)
            {
                ZfMessageUtil.ShowError("经度不能为空!");
                txeName.Focus();
                return;
            }
            if (txeLatitude.EditValue == null)
            {
                ZfMessageUtil.ShowError("纬度不能为空!");
                txeName.Focus();
                return;
            }
            if (txeElevation.EditValue == null)
            {
                ZfMessageUtil.ShowError("高程不能为空!");
                txeName.Focus();
                return;
            }
            if (string.IsNullOrEmpty(txeRotation.Text.Trim()))
            {
                ZfMessageUtil.ShowError("旋转不能为空!");
                txeName.Focus();
                return;
            }

            Project.Name = txeName.Text.Trim();
            Project.Longitude = Convert.ToDouble(txeLongitude.EditValue);
            Project.Latitude = Convert.ToDouble(txeLatitude.EditValue);
            Project.Elevation = Convert.ToDouble(txeElevation.EditValue);
            Project.Rotation = Convert.ToDouble(txeRotation.EditValue).AngleToRadian();
            Project.Remark = meRemark.Text.Trim();
            DialogResult = DialogResult.OK;
        }
    }
}